package com.zyy.chain;

/**
 * @Description: 类描述
 * @Author: zyy
 * @Date: 2023/08/09 17:55
 */
public abstract class Handler {
    protected static final int NUM_ONE = 1;
    protected static final int NUM_THREE = 3;
    protected static final int NUM_SEVEN = 7;

    //该领导处理的请假天数区间
    private int numStart;
    private int numEnd;

    //领导上还有领导
    private Handler nextHandler;

    //设置请假天数范围
    public Handler(int numStart) {
        this.numStart = numStart;
    }

    //设置请假天数范围
    public Handler(int numStart, int numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }

    //设置上级领导
    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    public void submit(LeaveRequest leaveRequest) {
        if (this.numStart == 0) {
            return;
        }
        if (leaveRequest.getNum() > this.numStart) {
            this.handleLeave(leaveRequest);
            //如果还有上级 并且请假天数超过当前领导的处理范围
            if (this.nextHandler != null && leaveRequest.getNum() > numEnd) {
                //继续提交
                this.nextHandler.submit(leaveRequest);
            } else {
                System.out.println("流程结束");
            }
        }

    }

    //各级领导处理请假条方法
    public abstract void handleLeave(LeaveRequest leaveRequest);

}
